Skip to content

apt_dpkg: exclude {usr/,}lib/modules and more from Contents-*.gz cache#596

Merged
bdrung merged 1 commit intocanonical:mainfrom
bdrung:reduce-memory
Apr 24, 2026
Merged

apt_dpkg: exclude {usr/,}lib/modules and more from Contents-*.gz cache#596
bdrung merged 1 commit intocanonical:mainfrom
bdrung:reduce-memory

Conversation

@bdrung
Copy link
Copy Markdown
Member

@bdrung bdrung commented Apr 23, 2026

The Contents-*.gz cache becomes bigger and bigger the longer a stable release ages (due to more and more kernel package versions in the archive).

Path jammy noble questing resolute
: 0 0 0 0
boot 4,654 2,647 366 137
lib/modules 10,206,350 5,492,830 475,055 9,120
usr/[^/]+/include 107,568 170,800 103,340 127,294
usr/include 278,938 271,587 295,470 298,389
usr/lib/modules 0 0 0 73,589
usr/share/cargo/registry 28,202 74,721 102,428 127,537
usr/share/doc 3,025,577 2,938,577 2,636,718 2,766,784
usr/share/gimp/.../help 38,220 73,845 78,120 85,216
usr/share/gocode 112,802 168,941 199,405 227,626
usr/share/help 121,470 124,824 118,948 119,346
usr/share/icons 605,862 659,375 715,984 753,986
usr/share/libreoffice/help 93,359 98,690 100,540 100,580
usr/share/locale 95,312 110,122 123,230 123,842
usr/share/man 149,353 165,310 175,262 177,041
usr/share/texlive 145,420 168,740 170,265 171,546
usr/src 39,533,381 21,538,896 2,201,315 420,916
var 15,759 35,438 37,204 37,552
current 13,711,111 9,541,912 4,444,324 4,268,204
new 3,365,393 3,839,911 3,725,751 3,909,851

This causes the cache to contain 13 million entries for jammy and to need more than 5 GiB of memory to retrace crashes.

Exclude the kernel directories usr/lib/modules and lib/modules, the help directories usr/share/libreoffice/help and usr/share/gimp/.../help, and the source code directory usr/share/cargo/registry from the cache. Simplify the exclusion rule by dropping :, boot, and var since those directory do not contain many entries. Note: The package fex in xenial contains a file named /:sexsend:sexget:.

This change reduced the cache creation time from 35.1 seconds down to 25.4 seconds for jammy amd64 on my Intel Core Ultra 9 285K desktop machine. The size reported by sys.getsizeof() reduced from 671 MB to 167 MB.

Bug: https://launchpad.net/bugs/2073787

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.51%. Comparing base (16d520b) to head (19cf32f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #596   +/-   ##
=======================================
  Coverage   84.51%   84.51%           
=======================================
  Files         104      104           
  Lines       20987    20988    +1     
  Branches     3218     3218           
=======================================
+ Hits        17738    17739    +1     
  Misses       2808     2808           
  Partials      441      441           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdrung
Copy link
Copy Markdown
Member Author

bdrung commented Apr 23, 2026

Verified that test_retrace_jammy_sandbox succeeds in a VM with only 2 GiB memory now.

@bdrung bdrung changed the title apt_dpkg: exclude {usr/,}lib/modules from Contents-*.gz cache apt_dpkg: exclude {usr/,}lib/modules and more from Contents-*.gz cache Apr 23, 2026
Copy link
Copy Markdown
Contributor

@Hyask Hyask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with just a little question.

Comment thread tests/unit/test_packaging_apt_dpkg.py
The Contents-*.gz cache becomes bigger and bigger the longer a stable
release ages (due to more and more kernel package versions in the
archive).

| Path                       |      jammy |      noble |   questing |   resolute |
|----------------------------|------------|------------|------------|------------|
| :                          |          0 |          0 |          0 |          0 |
| boot                       |      4,654 |      2,647 |        366 |        137 |
| lib/modules                | 10,206,350 |  5,492,830 |    475,055 |      9,120 |
| usr/[^/]+/include          |    107,568 |    170,800 |    103,340 |    127,294 |
| usr/include                |    278,938 |    271,587 |    295,470 |    298,389 |
| usr/lib/modules            |          0 |          0 |          0 |     73,589 |
| usr/share/cargo/registry   |     28,202 |     74,721 |    102,428 |    127,537 |
| usr/share/doc              |  3,025,577 |  2,938,577 |  2,636,718 |  2,766,784 |
| usr/share/gimp/.../help    |     38,220 |     73,845 |     78,120 |     85,216 |
| usr/share/gocode           |    112,802 |    168,941 |    199,405 |    227,626 |
| usr/share/help             |    121,470 |    124,824 |    118,948 |    119,346 |
| usr/share/icons            |    605,862 |    659,375 |    715,984 |    753,986 |
| usr/share/libreoffice/help |     93,359 |     98,690 |    100,540 |    100,580 |
| usr/share/locale           |     95,312 |    110,122 |    123,230 |    123,842 |
| usr/share/man              |    149,353 |    165,310 |    175,262 |    177,041 |
| usr/share/texlive          |    145,420 |    168,740 |    170,265 |    171,546 |
| usr/src                    | 39,533,381 | 21,538,896 |  2,201,315 |    420,916 |
| var                        |     15,759 |     35,438 |     37,204 |     37,552 |
| **current**                | 13,711,111 |  9,541,912 |  4,444,324 |  4,268,204 |
| **new**                    |  3,365,393 |  3,839,911 |  3,725,751 |  3,909,851 |

This causes the cache to contain 13 million entries for jammy and
to need more than 5 GiB of memory to retrace crashes.

Exclude the kernel directories `usr/lib/modules` and `lib/modules`, the
help directories `usr/share/libreoffice/help` and
`usr/share/gimp/.../help`, and the source code directory
`usr/share/cargo/registry` from the cache. Simplify the exclusion rule
by dropping `:`, `boot`, and `var` since those directory do not contain
many entries. Note: The package fex in xenial contains a file named
`/:sexsend:sexget:`.

This change reduced the cache creation time from 35.1 seconds down to
25.4 seconds for jammy amd64 on my Intel Core Ultra 9 285K desktop
machine. The size reported by `sys.getsizeof()` reduced from 671 MB
to 167 MB.

Bug: https://launchpad.net/bugs/2073787
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
@bdrung
Copy link
Copy Markdown
Member Author

bdrung commented Apr 24, 2026

Added some more entries to test_contents_path_filering to test the new exclusion; and rebased on main.

@bdrung bdrung merged commit 19cf32f into canonical:main Apr 24, 2026
19 checks passed
@bdrung bdrung deleted the reduce-memory branch April 24, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants